<template>
	<layout :loading="loadingData" pageKey="article" :title="data._id ? '修改文章':'新增文章'">
 
		<form @submit="submit" data-action="admin/article/save" data-back="/pages/article/list" data-clear="admin/article/list">

<view class="w100p pd10">
	<view class="fixAutoNoPd">
		
			<inputs name="x.title|标题" title="标题" :value="data.title"></inputs>
		
			
				<selects title="文章分类" :list="articletypeList" name="x.category_id|文章分类"
				:value="data.category_id" titleKey="name" valueKey="_id"></selects>
			<selects title="文章类型" :list="modelist" name="x.mode|文章类型"
			:value="data.mode||1" titleKey="name" valueKey="id"></selects>
					</view>
			
			<uploads title="略缩图" name="x.avatar" v-model="data.avatar" :count="1"></uploads>	
			<view class="fixAutoNoPd">
				
				<view>
					<selects title="文章状态" :list="articlestateList" name="x.article_status|文章状态"
					:value="data.article_status||0" titleKey="name" valueKey="id" ></selects>
					
				</view>
				<view>
					<selects title="评论开放" :list="commentList" name="x.comment_status|评论开放"
					:value="data.comment_status||0" titleKey="name" valueKey="id" ></selects>
					
				</view>
				<view class="pd10">
					<switchs  name="x.is_sticky|是否置顶" title="是否置顶" v-model="data.is_sticky" ></switchs>
					
				</view>
				<view class="pd10">
					<switchs  name="x.is_essence|是否加精" title="是否加精" v-model="data.is_essence" ></switchs>					
				</view>
			</view>					
			<!-- <inputs name="x.sort|排序" title="排序" type="number" :value="data.sort"></inputs> -->
			<lRichTextEditor class="pd20 w100p"   :value="data.content" 	@change="GetChange"></lRichTextEditor>
			
			<textareas style="display: none;"  title="内容"  name="x.content|内容"  v-model="data.content"   placeholder="必填"></textareas>			
			<textareas title="摘录" name="x.excerpt|摘录|empty"  v-model="data.excerpt"  :maxlength="200"  placeholder="选填"></textareas>
						
			<view class="fixAuto">
				<view >
					 <inputs name="x.view_count|阅读量" title="阅读量" type="number" :value="data.view_count||0"></inputs>
				</view>
				<view>
					 <inputs name="x.like_count|点赞量" title="点赞量" type="number" :value="data.like_count||0"></inputs>					
				</view>
				<view>
					<inputs name="x.comment_count|评论量" title="评论量" type="number" :value="data.comment_count||0"></inputs>					
				</view>
			</view>
			
			<labels class="mt40">
				<inputs type="hidden" name="x._id" :value="id" v-if="id"></inputs>
				<button class="btn greenBg w80" form-type="submit">{{ !data._id ? '保存' : '修改'}}</button>
				<button class="btn grayBg line w80" @click="bcc.goBack()">取消</button>
			</labels>
			</view>
		</form>

	</layout>
</template>

<script>
	
	
	
	export default {
		
		data() {
			return {
				loadingData : true ,
				articletypeList:[],
				articlestateList:[{"id":"0","name":"草稿"},{"id":"1","name":"发布"}],
				commentList:[{"id":"0","name":"关闭评论"},{"id":"1","name":"开放评论"}],
				modelist:[{"id":"1","name":"文章类"},{"id":"2","name":"图文类"}],
				id : '' ,
				data : {
					_id:"",
					content:'',
					excerpt:'',
					title:"",
					avatar:"",
					category_id:'',
					article_status:'',
					comment_status:'',
					is_sticky:'',
					is_essence:''
				},
				
				
			}
		},
		
		onLoad(params) {
			this.id = params.id ;
			this.loadData();
			this.loadArticleTypeData();
			
			
		},
		
		onShow() {
			
			
		},
		methods: {
			
			GetChange(res) {			
				
				this.$set(this.data, 'content', res)
				
				if(!this.id){
					let excerpt=res.replace(/<[^>]+>/g,"").replace(/\r/g,'').replace(/\n/g,'');
				this.$set(this.data, 'excerpt', excerpt.substring(0,200));	
							}
				//console.log(this.data.excerpt);
				
			},
			submit:function(e){
							
				this.bcc.submit(e);
			},
			
			loadData : function(e){
				var that = this ;
				var data = {
					id : this.id 
				};
				this.bcc.call({
					url : 'admin/article/info' ,
					data : data ,
					success : res => { 
						this.data = res.data || {};
						// this.content=this.data.content;
						// this.excerpt=this.data.excerpt;
						// this.typeList = res.typeList ;
						this.loadingData = false ;
					}
				});
			},
			loadArticleTypeData : function(e){
				var that = this ;
				var data = {
					
				};
				this.bcc.call({
					url : 'admin/cate/list' ,
					data : data ,
					success : res => {						
						this.articletypeList = res.list ;
						
					}
				});
			},
			
		}
	}
</script>

<style>

</style>
